﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - QuestionQuota" 
*/ 

component 
	displayname="public.service.db.senate.sequence.QuestionQuota" 
	output=false 
	accessors=true 
	{

	property type="string" name="questionID" hint="问卷号";
	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = getQuestionID() & numberFormat(1, "0__");
		sql = "	SELECT
					q.quo_id
				FROM
					t_quota q
				WHERE
					q.quo_id LIKE :condition 
				ORDER BY
					q.quo_id DESC";

		queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		queryObj.addParam(name = "condition", value = getQuestionID() & "___", cfsqltype = "cf_sql_char");
		rs_check = queryObj.execute(sql = sql).getResult();
		
		/* 
			主键生成规则 
			
			8位问卷编号 + 3位流水号
			
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = getQuestionID() & numberFormat((right(rs_check.quo_id, 3) + 1), "0__");
			
		}

		return nextID;
	}

}

</cfscript>